<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('wechat_openids', function (Blueprint $table) {
            $table->id();
            $table->string('openid')->comment('微信openid');
            $table->foreignId('freelancer_id')
                ->nullable()
                ->constrained('freelancers')
                ->nullOnDelete()
                ->comment('关联灵工ID');
            $table->timestamps();

            $table->unique('openid', 'wechat_openids_openid_unique');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('wechat_openids');
    }
};
